package net.xdclass.service.impl;

import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import net.xdclass.dto.ReportDTO;
import net.xdclass.mapper.ReportMapper;
import net.xdclass.model.ReportDO;
import net.xdclass.req.ReportSaveReq;
import net.xdclass.service.ReportService;
import net.xdclass.util.SpringBeanUtil;
import org.springframework.stereotype.Service;

@Service
@Slf4j
public class ReportServiceImpl implements ReportService {

    @Resource
    private ReportMapper reportMapper;

    @Override
    public ReportDTO save(ReportSaveReq req) {
        ReportDO reportDO = SpringBeanUtil.copyProperties(req, ReportDO.class);
        reportMapper.insert(reportDO);
        //下面这两种写法应该都可以吧
        ReportDTO reportDTO = ReportDTO.builder()
                .id(reportDO.getId())
                .projectId(reportDO.getProjectId())
                .name(reportDO.getName())
                .build();
//        ReportDTO reportDTO = SpringBeanUtil.copyProperties(reportDO, ReportDTO.class);

        return reportDTO;
    }
}
